package net.zui.entity;

import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics2D;
import java.awt.Point;

import net.zui.Option;
import net.zui.comp.ZBase;
import net.zui.enume.TextAlign;
import net.zui.util.UDraw;

public class ZTextRender {
	protected Font font;
	protected Color color;
	protected String text;
	protected TextAlign align=TextAlign.center;
	
	public ZTextRender(String text) {
		this(Option.getFont(), Option.getFontColor(), text);
	}
	
	public ZTextRender(Font font, Color color, String text) {
		this.font = font;
		this.color = color;
		this.text = text;
	}
	
	public void draw(Graphics2D g, ZBase base) {
		Point p = UDraw.alignString(text, font, base.getOuterWidth(), base.getOuterHeight(), Option.padding, align);
		g.setColor(color);
		g.setFont(font);
		g.drawString(text, p.x, p.y);
	}
	
	public static class Shadow extends ZTextRender{
		private int left=0,top=0;
		private Color shadowColor=UDraw.web("eee");
		private Font shadowFont;
		
		public Shadow(String text) {
			this(text,Option.getFontColor(),Option.getFont());
		}

		public Shadow(String text,Color color) {
			super(Option.getFont(), color, text);
		}
		
		public Shadow(String text, Color color,Font font) {
			super(font, color, text);
		}
		
		public Shadow(String text, Color color,Font font,Color shadowColor) {
			super(font, color, text);
			this.shadowColor=shadowColor;
		}
		
		public Shadow(String text, Color color,Color shadowColor) {
			super(Option.getFont(), color, text);
			this.shadowColor=shadowColor;
		}
		
		@Override
		public void draw(Graphics2D g, ZBase base) {
			Point p = UDraw.alignString(text, font, base.getOuterWidth(), base.getOuterHeight(), Option.padding, align);
			shadowFont=new Font(font.getName(), Font.BOLD+(font.isItalic()?Font.ITALIC:0), font.getSize());
			g.setFont(shadowFont);
			g.setColor(shadowColor);
			g.drawString(text, p.x+left, p.y+top);
			g.setFont(font);
			//System.out.println(font);
			g.setColor(color);
			g.drawString(text, p.x, p.y);
		}

		public Color getShadowColor() {
			return shadowColor;
		}

		public void setShadowColor(Color shadowColor) {
			this.shadowColor = shadowColor;
		}
	}

	public Font getFont() {
		return font;
	}

	public void setFont(Font font) {
		this.font = font;
	}

	public Color getColor() {
		return color;
	}

	public void setColor(Color color) {
		this.color = color;
	}

	public String getText() {
		return text;
	}

	public void setText(String text) {
		this.text = text;
	}

	public TextAlign getAlign() {
		return align;
	}

	public void setAlign(TextAlign align) {
		this.align = align;
	}
}
